package com.party.mem.biz.index;

import com.google.common.collect.Lists;
import com.party.common.paging.Page;
import com.party.core.model.YesNoStatus;
import com.party.core.model.article.Article;
import com.party.core.model.resource.Resource;
import com.party.core.model.system.Dict;
import com.party.core.model.system.DictEnum;
import com.party.core.service.article.IArticleService;
import com.party.core.service.resource.IResourceService;
import com.party.core.service.system.IDictService;
import com.party.mem.biz.file.FileBizService;
import com.party.mem.web.dto.index.IndexDictContentOutput;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 首页业务接口
 * Created by wei.li
 *
 * @date 2017/2/22 0022
 * @time 15:40
 */
@Service
public class IndexBizService {

    @Autowired
    IResourceService resourceService;

    @Autowired
    private FileBizService fileBizService;

    @Autowired
    private IDictService dictService;

    @Autowired
    private IArticleService articleService;
    
    public List<Resource> getPartner(){
    	// 合作伙伴
		Resource resource = new Resource();
		resource.setType("partner");
		List<Resource> resources = resourceService.webListPage(resource, null, new Page(1, 16));
		return resources;
    }

    /**
     * 获取视频
     * @return
     */
    public List<Resource> getVideo(){
        Resource resource = new Resource();
        resource.setType("video");
        List<Resource> resources = resourceService.webListPage(resource, null, new Page(1, 9));
        return resources;
    }

    /**
     * 文章类型和文章列表
     *
     * @return
     */
    public List<IndexDictContentOutput> typeWithArticleList(Page page) {
        List<IndexDictContentOutput> outputList = Lists.newArrayList();
        Dict dict = new Dict();
        dict.setType(DictEnum.ARTICLE_TYPE.getCode());
        dict.setOpenStatus(YesNoStatus.YES.getCode());
        List<Dict> dicts = dictService.list(dict);
        for (Dict dd : dicts) {
            Article article = new Article();
            article.setArticleType(dd.getValue());
            List<Article> articles = articleService.listPage(article, page);
            for (Article aa : articles) {
                aa.setContent(null);
            }
            IndexDictContentOutput output = new IndexDictContentOutput();
            output.setTypeName(dd.getLabel());
            output.setTypeValue(dd.getValue());
            output.setArticles(articles);
            outputList.add(output);
        }
        return outputList;
    }
}
